package tool

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
	"time"
)

const (
	SUCCESS int = 200
	ERROR   int = -1
)

func Success(ctx *gin.Context, v interface{}) {
	ctx.JSON(http.StatusOK, map[string]interface{}{
		"code": SUCCESS,
		"msg":  "SUCCESS",
		"data": v,
	})
}

func Error(ctx *gin.Context, v interface{}) {
	ctx.JSON(http.StatusOK, map[string]interface{}{
		"code": ERROR,
		"msg":  "ERROR",
		"data": v,
	})
}

func CheckError(ctx *gin.Context, err error) {
	if err != nil {
		fmt.Println(err.Error())
		//os.Exit(1)
	}
}

//获取日期
func GetDay() string {
	template := "20060102"
	return time.Now().Format(template)
}

//获取当前纳秒时间戳
func GetUnixNano() int64 {
	return time.Now().UnixNano()
}

// 获取当前日期时间
func GetDate() string {
	template := "2006-01-02 15:04:05"
	return time.Now().Format(template)
}
